﻿/*----------------------------------------------------------------
           // Copyright (C) 2008 安华顺通(北京)科技有限公司
           // 版权所有。 
           //
           // 文件名：SysPropertyUIEditor.cs
           // 文件功能描述：属性编辑器。
           //
           // 
           // 创建标识：杨波20080928
           //
           // 修改标识：
           // 修改描述：
           //
           // 修改标识：
           // 修改描述：
//----------------------------------------------------------------*/

#region UsingStatements

using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
using System.Windows.Forms;      

#endregion

namespace RuleCode.ObjectTree
{
    public class SysPropertyMethodUIEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(
            ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        #region Edit Value

        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider,
                                         object value)
        {
            //MySharp.MySharpIDE methodEditor = new MySharp.MySharpIDE();
            ////if (value != null)
            ////methodEditor.Value = value.ToString();
            //methodEditor.Show();
            //methodEditor.MdiParent = Util.MdiParent;


            //return methodEditor.Value;
            return 1;
        }

        #endregion

        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return false;
            //return base.GetPaintValueSupported(context);
        }
    }

    public class SysPropertyFileNameEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(
            ITypeDescriptorContext context)
        {
            if (context != null)
                return UITypeEditorEditStyle.Modal;

            return UITypeEditorEditStyle.None;
        }

        //[RefreshProperties(RefreshProperties.All)]

        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context == null || provider == null || context.Instance == null)
                return base.EditValue(provider, value);

            FileDialog fd = new OpenFileDialog();
            fd.CheckFileExists = true;
            fd.CheckPathExists = true;
            fd.Title = "Select Filename";
            fd.FileName = (value as string);
            fd.Filter = "All Files (*.*)|*.*";

            if (fd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(fd.FileName))
                {
                    value = fd.FileName;
                }
            }

            return value;
        }
    }

    public class SysPropertyFontEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(
            ITypeDescriptorContext context)
        {
            //if (context != null)
            return UITypeEditorEditStyle.Modal;

            //return UITypeEditorEditStyle.None;
        }

        //[RefreshProperties(RefreshProperties.All)]
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context == null || provider == null || context.Instance == null)
                return base.EditValue(provider, value);

            FontDialog fd = new FontDialog();
            fd.AllowSimulations = true;
            fd.AllowVectorFonts = true;
            fd.AllowVerticalFonts = true;
            if (fd.ShowDialog() == DialogResult.OK)
            {
                value = fd.Font.Name;
            }

            return value;
        }
    }

    public class LabelPropertyEditor : UITypeEditor
    {
        [RefreshProperties(RefreshProperties.All)]
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            //return base.EditValue(context, provider, value);
            LanguageSelectForm labelEditForm = new LanguageSelectForm();
            if (value != null)
                labelEditForm.Value = value.ToString();
            labelEditForm.ShowDialog();


            return labelEditForm.Value;
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
            //return base.GetEditStyle(context);
        }

        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return false;
            //return base.GetPaintValueSupported(context);
        }
    }
}